package com.mtl.article.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.mtl.common.tool.api.R;
import com.mtl.common.tool.model.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.mtl.article.domain.Article;
import com.mtl.article.service.IArticleService;
import java.util.List;
import java.util.Arrays;

/**
 * 文章管理 控制器
 *
 * @author lsc
 * @since 2019-08-09
 */
@RestController
@RequestMapping("/admin/article")
@Api(value = "文章管理", tags = "文章管理接口")
public class ArticleController {
    @Autowired
	private IArticleService articleService;

	/**
	* 详情
	*/
	@GetMapping("/detail")
	@ApiOperation(value = "详情", notes = "传入article", position = 1)
	public R<Article> detail(Integer id) {
		Article detail = articleService.findById(id);
		return R.data(detail);
	}

	/**
	* 分页 文章管理
	*/
	@GetMapping("/page")
	@ApiOperation(value = "分页", notes = "传入article", position = 2)
	public R<Page<Article>> page(Integer page,Integer size,String search) {
		Page<Article> pages = articleService.findPage(page,size,search);
		return R.data(pages);
	}

	/**
	* 新增或修改 文章管理
	*/
	@PostMapping("/submit")
	@ApiOperation(value = "新增或修改", notes = "传入article", position = 6)
	public R submit(@RequestBody Article article) {
		return R.status(articleService.saveOrUpdate(article));
	}

	/**
	* 删除 文章管理
	*/
	@PostMapping("/remove")
	@ApiOperation(value = "删除", notes = "传入ids", position = 7)
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestBody Integer[] ids) {
		return R.status(articleService.deleteBatch(Arrays.asList(ids)));
	}
	/**
	 * 图片 文章管理
	 */
	@PostMapping("/findImg")
	@ApiOperation(value = "图片", notes = "", position = 8)
	public R<Page<Article>> findByImg(Integer page,Integer size) {
		Page<Article> pages = articleService.findByImg(page,size);
		return R.data(pages);
	}
	/**
	 * 排序 文章管理
	 */
	@PostMapping("/findOrder")
	@ApiOperation(value = "排序", notes = "", position = 9)
	public R<Page<Article>> findByOrder(Integer page,Integer size,String order,String sort,Boolean img,Integer sortid) {

		Page<Article> pages = articleService.findOrder(page,size,order,sort,img,sortid);
		return R.data(pages);
	}

}
